using Common.Commands.AccountCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class AccountProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddAccount()
        {
            var command = new AddAccount
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Music,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "description",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<AccountView>>();
            var accountView = repo.GetById(command.Id);

            Assert.AreEqual(accountView.Name, command.Name);
        }

        [Test]
        public void ShouldDeleteAccount()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Electronics,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);

            var command = new DeleteAccount(account.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AccountView>>();
            var accountView = repo.GetById(command.Id);

            Assert.IsNull(accountView);
        }

        [Test]
        public void ShouldUpdateAccount()
        {
            var account = new Account
            {
                Id = GuidComb.New(),
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.InternetPublishing,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                BillingLatitude = 0,
                BillingLongitude = 0,
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                ShippingLatitude = 0,
                ShippingLongitude = 0,
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "Description",
                ImageData = ImageUtility.NoImageData
            };

            Persist(account);

            var command = new UpdateAccount
            {
                Id = account.Id,
                Name = "Priya",
                AccountType = AccountType.Vendor,
                AccountNumber = "accountnumber",
                Industry = Industry.Banking,
                BillingStreet = "billingstreet",
                BillingCity = "city",
                BillingState = "state",
                BillingPostalCode = "code",
                BillingCountry = "county",
                ShippingStreet = "sstreet",
                ShippingCity = "scity",
                ShippingState = "sstate",
                ShippingPostalCode = "Scode",
                ShippingCountry = "scountry",
                Phone = "phone",
                Mobile = "mobile",
                Fax = "fax",
                Website = "web",
                Email = "email@email.com",
                Description = "description",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<AccountView>>();
            var accountView = repo.GetById(command.Id);

            Assert.AreEqual(accountView.Id, account.Id);
        }
    }
}